import java.io.File;
import java.util.List;

public class ThirtyMinutesConvertor {
	
	public void convert(String srcFolder, String tempFolder, String historyFolder, String desFolder) {
		List<String> zippedFiles = FileUtils.generateFileList(srcFolder, ".zip");
		if (zippedFiles == null)
			return;
		//upzip the source zip files
		for (String fileName : zippedFiles) {
			FileUtils.unzipAndMove(srcFolder, fileName, srcFolder, historyFolder);
		}
		//process the unzipped csv files and move them to history folder
		List<String> unzippedFiles = FileUtils.generateFileListExludeSuffix(srcFolder, ".zip");
		FileProcessor processor = new FileProcessorThirtyMinutes();
		for (String fileName : unzippedFiles)
			processor.processFile(srcFolder, fileName, tempFolder, historyFolder);
		//zip the processed csv files to desternation folder and move them to history folder
		unzippedFiles = FileUtils.generateFileList(tempFolder);
		for (String fileName: unzippedFiles) {
			FileUtils.zip(tempFolder, fileName, desFolder);
			FileUtils.moveIntoFolderReplaceExisting(historyFolder, tempFolder + File.separator + fileName);
		}
	}
	
	public void test() {
		LogUtils.printMemoryUsage(ThirtyMinutesConvertor.class);
		String ORIGINAL_FOLDER = "C:\\Users\\myuan\\Documents\\30minutes";
		String PRE_FOLDER = "C:\\Users\\myuan\\Documents\\30minutes\\forpreproc";
		String HISTORY_FOLDER = "C:\\Users\\myuan\\Documents\\30minutes\\history";
		String POST_FOLDER = "C:\\Users\\myuan\\Documents\\30minutes\\postproc";
		
/*		String ORIGINAL_FOLDER = "C:\\sharedfolder\\30minutes";
		String PRE_FOLDER = "C:\\sharedfolder\\30minutes\\forpreproc";
		String HISTORY_FOLDER = "C:\\sharedfolder\\30minutes\\history";
		String POST_FOLDER = "C:\\sharedfolder\\30minutes\\postproc";*/
		
		convert(ORIGINAL_FOLDER, PRE_FOLDER, HISTORY_FOLDER, POST_FOLDER);
		System.out.println("finished processed!");
	}
	
	public static void main(String[] args) {
		
//		if (args == null || args.length != 4) {
//			System.out.println("Usage: java -jar selectSolution.jar OriginalFolder PreFolder HistoryFolder PostFolder ... ");
//			System.exit(0);
//		}
		ThirtyMinutesConvertor convertor = new ThirtyMinutesConvertor();
//		convertor.convert(args[0], args[1], args[2], args[3]);
		convertor.test();
		System.out.println("finished processed!");
	}

}
